from flask import Flask, request,json
from flask import render_template
from static import getIMEI
from static import getCode
#from static import getDocument
from static.getDocument import get_document
import requests
import qrcode

app = Flask(__name__)


@app.route('/')
def hello_world():
    return render_template('index.html')

@app.route('/imei')
def getIMEIs():
    imei = getIMEI.genMassImei("12345123451234", 1000)
    return imei

@app.route('/ProductNo/<env>')
def getProductNo(env):
    if env == "uat":
        url = 'http://47.96.53.33/operationservice/product/receipt/generate/productNo'
    else:
        url = 'http://120.55.138.130/operationservice/product/receipt/generate/productNo'
    r = requests.get(url)
    #print(r.json())
    return r.json().get("data")


@app.route('/qrcode')
def getCodes():
    text = getCode.make_code(str(getIMEI.genMassImei("12345123451234",1000)))
    #print("11111111")
    #print(text)
    return text

@app.route('/document',methods=["POST"])
def getDocument():
    #document = getDocument.get_document("I2019082814418720842984","fat")
    data = request.get_data()
    print("11111",data,data.decode('utf-8'))
    json_data = json.loads(data.decode('utf-8'))
    print("222",json_data)
    shipment = json_data.get("shipmentNo")
    print(shipment)
    env = json_data.get("env")
    print(env)
    document = get_document(shipment,env)
    #print(request.form)
    #print(document)
    return document



if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)
